package cm.Introspector;

import cm.Serializer.DataMaskingSerializer;
import cm.annotation.DataMasking;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: yxh
 * @Description: 自定义AnnotationIntrospector，适配我们自定义注解返回相应的Serialize -注解脱敏
 * @Date: Created in 2022/8/29 10:47
 * @Modified By:
 */
@Slf4j
public class DataMaskingAnnotationIntrospector extends NopAnnotationIntrospector {

    @Override
    public Object findSerializer(Annotated am) {
        DataMasking annotation = am.getAnnotation(DataMasking.class);
        if (annotation != null) {
            return new DataMaskingSerializer(annotation.maskFunc().operation());
        }
        return null;
    }
}
